package castle;

import java.util.HashMap;

public class Room {
	private String description;
	private HashMap<String, Room> exits = new HashMap<String,Room>();//使用哈希来代替 room northExit，，，，，，

	public Room(String description) {
		this.description = description;
	}
	
	public void setExit(String dir, Room room) {
		exits.put(dir, room);//设置方向  room northExit，，，，，，
	}
	
	@Override
	public String toString() {
		return description;
	}

	// 返回房间的所有出口
	public String getExitDesc() {//解开耦合
		StringBuffer sb = new StringBuffer();//字符串
		for (String dir:exits.keySet()) {//拿到给每一个钥匙，并且加入dir
			sb.append(dir);//sb+=dir 字符串操作，产生一个新的字符串，省空间
			sb.append(" ");
		}
		return sb.toString();
	}
	// 说明房间的某个方向有没有东西
	public Room getExit(String direction) {
		return exits.get(direction);
	}
}
